using System.Collections;
using WatiN.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QAHelper.Common;

namespace WatiNTest
{
	[TestClass]
    public class TestLogin: TestBase
    {

        #region Constructor

        public TestLogin(TestCaseStructure testContent, ArrayList headerList)
        {
            testCaseStructure = testContent;
            headerListBase = headerList;
            
        }

        #endregion

        #region Test Case Login_Success

        [TestMethod]

        public void LoginSuccess()
        {
            int noOfFields=0;
            ArrayList tempList = tempTestData;//CommonHelper.GetDataFromDictionary(tempTestData, 0);
            WatiNInputHelper.SetPageInput(TestManager.browser, tempList, out noOfFields);
            TestManager.browser.Button(Find.ByName("ctl00$MainContent$LoginButton")).Click();
            DictionaryEntry dataRow = (DictionaryEntry)tempList[0];
            string userName = dataRow.Value.ToString().Trim();

            string result = string.Empty;
            string actualResult = "&nbsp;";

            if (TestManager.browser.Para(Find.ById("message")).Text.Trim().Equals(scenario.ExpectedResult))
            {
                result = "Pass";                
            }
            else
                result = "Fail";
            actualResult = TestManager.browser.Para(Find.ById("message")).Text.Trim();            

            testCaseStructure = QAHelper.Common.CommonHelper.UpdateTestCaseStructure(result, actualResult,testCaseStructure,scenario);
        }

        #endregion

        #region Test Blank Username

        [TestMethod]

        public void LoginBlankUsername()
        {
            int noOfFields = 0;
            ArrayList tempList = tempTestData;
            WatiNInputHelper.SetPageInput(TestManager.browser, tempList, out noOfFields);
            TestManager.browser.Button(Find.ByName("ctl00$MainContent$LoginButton")).Click();
            DictionaryEntry dataRow = (DictionaryEntry)tempList[0];
            string userName = dataRow.Value.ToString().Trim();
            
            string result = string.Empty;
            string actualResult = "&nbsp;";

            if (TestManager.browser.Span(Find.ById("MainContent_UserNameRequired")).Text.Trim().Equals(scenario.ExpectedResult))
            {
                result = "Pass";
            }
            else
                result = "Fail";
            actualResult = TestManager.browser.Span(Find.ById("MainContent_UserNameRequired")).Text.Trim();

            testCaseStructure = QAHelper.Common.CommonHelper.UpdateTestCaseStructure(result, actualResult, testCaseStructure, scenario);

        }
        #endregion

        #region Test Blank Password

        [TestMethod]

        public void LoginBlankPassword()
        {
            int noOfFields = 0;
            ArrayList tempList = tempTestData;
            WatiNInputHelper.SetPageInput(TestManager.browser, tempList, out noOfFields);
            TestManager.browser.Button(Find.ByName("ctl00$MainContent$LoginButton")).Click();
            DictionaryEntry dataRow = (DictionaryEntry)tempList[0];
            string userName = dataRow.Value.ToString().Trim();

            string result = string.Empty;
            string actualResult = "&nbsp;";

            if (TestManager.browser.Span(Find.ById("MainContent_PasswordRequired")).Text.Trim().Equals(scenario.ExpectedResult))
            {
                result = "Pass";
            }
            else
                result = "Fail";
            actualResult = TestManager.browser.Span(Find.ById("MainContent_PasswordRequired")).Text.Trim();

            testCaseStructure = QAHelper.Common.CommonHelper.UpdateTestCaseStructure(result, actualResult, testCaseStructure, scenario);

        }
        #endregion



    }
}